package com.logic.modular.act.cultivate;

import cn.hutool.core.lang.Pair;
import com.comment.pojo.domain.logic.core.CoreTaskConfig;
import com.comment.util.message.ResponseResult;
import com.logic.comment.util.JwtUtils;
import com.logic.modular.game.season.server.domain.PlayerSeason;
import com.logic.modular.game.season.server.service.impl.PlayerSeasonServiceImpl;
import com.logic.modular.gameCore.season.info.domain.CoreSeasonAward;
import com.logic.modular.gameCore.season.info.service.impl.CoreSeasonAwardServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 赛季
 */
@Api(tags = "赛季")
@Validated
@RestController
@RequestMapping("/seasonAct")
public class SeasonAction {
    @Resource
    private PlayerSeasonServiceImpl seasonService;

    @ApiOperation("查看战令任务")
    @PostMapping("/viewBattleOrderTasks")
    public ResponseResult<List<CoreTaskConfig>> viewBattleOrderTasks(
    ) {
        return ResponseResult.success(seasonService.viewBattleOrderTasks());
    }

    @ApiOperation("查看战令等级奖励")
    @PostMapping("/viewBattleOrderLevelRewards")
    public ResponseResult<List<CoreSeasonAward>> viewBattleOrderLevelRewards(
    ) {
        return ResponseResult.success(CoreSeasonAwardServiceImpl.listCache());
    }

    @ApiOperation("查看领取记录")
    @PostMapping("/viewSeasonProgress")
    public ResponseResult<PlayerSeason> viewSeasonProgress(
            @RequestHeader String token
    ) {
        return ResponseResult.success(seasonService.obtain(JwtUtils.getPlayerId(token)));
    }
    @ApiOperation("当前赛季开始结束时间戳")
    @PostMapping("/obtainTheStartAndEndTimesOfTheSeason")
    public ResponseResult<Pair<Long, Long>> obtainTheStartAndEndTimesOfTheSeason(
    ) {
        return ResponseResult.success(seasonService.obtainTheStartAndEndTimesOfTheSeason());
    }

    @ApiOperation("领取等级奖励")
    @PostMapping("/claimLevelRewards")
    public ResponseResult<?> claimLevelRewards(
            @RequestHeader String token,
            @RequestBody  @Valid SeasonActionVo.ClaimLevelRewards vo
    ) {
        seasonService.claimLevelRewards(JwtUtils.getPlayerId(token), vo.level, vo.lv,vo.bagItemId);
        return ResponseResult.success();
    }
    @ApiOperation("购买等级")
    @PostMapping("/purchaseLevel")
    public ResponseResult<?> purchaseLevel(
            @RequestHeader String token,
            @RequestBody @Valid SeasonActionVo.purchaseLevel vo
    ) {
        return ResponseResult.success( seasonService.purchaseLevel(JwtUtils.getPlayerId(token), vo.level));
    }
}
